package demo.practice.bit;

public class P477 {

    public int totalHammingDistance(int[] nums) {
        int res=0;
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                res+= getHamming(nums[i],nums[j]);
            }
        }
        return res;
    }


    private int getHamming(int a,int b){
        int y= a^b;
        int res=0;
        while (y>0){
            res+= (y&1);
            y>>=1;
        }
        return res;
    }
}
